<include file="Public/header"/>
<div class="x-body">
    <form class="layui-form" action="{:U('update')}" method="post">
        <!--<div class="layui-form-item">-->
            <!--<label for="username" class="layui-form-label">-->
                <!--<span class="x-red"></span>上级分类-->
            <!--</label>-->
            <!--<div class="layui-input-inline">-->
                <!--<select name="pid">-->
                    <!--<option value="0">顶级分类</option>-->
                    <!--<volist name="list" id="vo">-->
                        <!--<option value="{$key}" <php>if($data['pid'] == $key) echo 'selected'</php>>{$vo}</option>-->
                    <!--</volist>-->

                <!--</select>-->
            <!--</div>-->
            <!--<div class="layui-form-mid layui-word-aux">-->
                <!--<span class="x-red"></span>-->
            <!--</div>-->
        <!--</div>-->
        <div class="layui-form-item">
            <label for="sort" class="layui-form-label">
                <span class="x-red"></span>图片
            </label>
            <div class="layui-input-inline">
                <div class="layui-upload-list">
                    <input type="hidden" name="icon"  value="{$data['icon']}" >
                    <img class="layui-upload-img" style="width: 100px;" id="avatar-preview" src="{$data['icon']}">
                    <p id="demoText"></p>
                </div>
                <button type="button" class="layui-btn" id="avatar-btn">
                    <i class="layui-icon">&#xe67c;</i>上传图片
                </button>
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red"></span>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="name" class="layui-form-label">
                <span class="x-red">*</span>跳转类型
            </label>
            <div class="layui-input-inline">
                <select name="type" id="type" lay-filter="type">
                    <option value="1" <php>if($data['type'] == 1) echo 'selected'</php>>不跳转</option>
                    <option value="2" <php>if($data['type'] == 2) echo 'selected'</php>>内部跳转</option>
                    <option value="3" <php>if($data['type'] == 3) echo 'selected'</php>>跳转到外部小程序</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item ishow_2">
            <label for="dataid" class="layui-form-label">
                内部跳转链接
            </label>
            <div class="layui-input-inline">
                <input type="text" id="url" name="url"
                       autocomplete="off" value="{$data['url']['url']}" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                /pages/home/detail?id=商品ID【商品详情】<br>
                /pages/home/notice?id=公告ID【公告】<br>

            </div>

        </div>


        <div class="layui-form-item ishow_3">
            <label for="appid" class="layui-form-label">
                小程序appid
            </label>
            <div class="layui-input-inline">
                <input type="text" id="appid" name="appid"
                       autocomplete="off" value="{$data['url']['appid']}" class="layui-input">
            </div>

        </div>


        <div class="layui-form-item ishow_3">
            <label for="path" class="layui-form-label">
                小程序路径
            </label>
            <div class="layui-input-inline">
                <input type="text" id="path" name="path"
                       autocomplete="off" value="{$data['url']['path']}" class="layui-input">
            </div>

        </div>

        <div class="layui-form-item ishow_3">
            <label for="param" class="layui-form-label">
                小程序参数
            </label>
            <div class="layui-input-inline">
                <input type="text" id="param" name="param"
                       autocomplete="off" value="{$data['url']['param']}" class="layui-input">
            </div>

        </div>



        <div class="layui-form-item">
            <label class="layui-form-label">显示</label>
            <div class="layui-input-block">
                <input type="checkbox" name="status" <php>if($data['status'] == 1 || !$data['status']) echo 'checked'</php> lay-skin="switch">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="sort" class="layui-form-label">
                <span class="x-red"></span>排序
            </label>
            <div class="layui-input-inline">
                <input type="text" id="sort" name="sort"
                       autocomplete="off" value="{$data['sort']|default=0}" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red"></span>
            </div>
        </div>
        <input type="hidden" name="id"  value="{$data['id']}">




        <div class="layui-form-item">
            <label for="L_repass" class="layui-form-label">
            </label>
            <button  class="layui-btn" lay-filter="submit" lay-submit="submit">
                保存
            </button>
        </div>
    </form>

</div>
<script>



    // var selectindex = $('#type').val();
    // var index = selectindex ? selectindex:'{$data['type']}';

   // alert(index);
   //  $('.show_'+index).css('display','none');

    layui.use(['upload','form','jquery'], function(){

        var $ = layui.$;
        var form = layui.form;
        var s = '{$data['type']}';

        $('.ishow_2').hide();
        $('.ishow_3').hide();
        $('.ishow_'+s).show();

        form.on('select(type)', function(data){
            var selectindex = data.value;
            //$('#ccc_'+selectindex).hide();
                 //$('.ishow_1').hide();
                 $('.ishow_2').hide();
                 $('.ishow_3').hide();
                 $('.ishow_'+selectindex).show();
        });



        var upload = layui.upload;

        //执行实例
        var uploadInst = upload.render({
            elem: '#avatar-btn'
            ,url: "{:U('Upload/uploadpic')}"
            ,data:{
                name:'img'

            }
            ,field:'img'
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#avatar-preview').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){


                if(res.code!=0){
                    layer.msg(res.msg,{icon: 5});

                }
                //上传成功
                if(res.code==0 ){
                    layer.msg('上传成功',{icon: 6});
                    $("[name='icon']").val(res.data);

                }

            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        });
    });
</script>
<include file="Public/footer"/>